<?php

namespace Data;

class Breed extends Base {

	public function getPinyinOneToBreed() {
		$all = $this->order('IsHot Desc, Sort Desc')->findAll();
		$result = array();
		foreach ($all as $arr) {
			$p = strtoupper($arr['Pinyin'][0]);
			$result[$p][$arr['Id']] = $arr;
		}
		ksort($result);
		return $result;
	}

	public function getBreedName() {
		$all = $this->order('IsHot Desc, Sort Desc, Pinyin Asc')->findAll();
		$result = array();
		foreach ($all as $val) {
			$result[$val['Id']] = $val['Name'];
		}
		return $result;
	}

	public function getBreedIdByName($breed) {
		$where = array('Name' => $breed);
		$one = $this->where($where)->findOne();
		return $one ? $one['Id'] : 0;
	}

	public function getBreedIdsByNames($breedNames) {
		$where = array('Name in' => $breedNames);
		$result = $this->where($where)->findAll('Id');
		$result = array_keys($result);
		return $result;
	}

	public function getNameById($id) {
		$where = array('Id' => $id);
		$one = $this->where($where)->findOne();
		return $one ? $one['Name'] : 0;
	}

	public function getByIds($breedIds) {
		$where = array('Id in' => $breedIds);
		$result = $this->where($where)->findAll('Id');
		return $result;
	}

	public function getNameByIds($breedIds) {
		$where = array('Id in' => $breedIds);
		$result = $this->where($where)->findAll('Name');
		return array_keys($result);
	}

}